<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
function transform (input) {
  const [path, query] = input.split('?');
  const [id] = path.split('/').slice(-1);
  const params = {
    id,
    ...query.split('&').reduce((prev, current) => {
      const [key, value] = current.split('=');
      prev[key] = value;
      return prev;
    }, {}),
  };
  return params;
}

console.log( transform('xxxx/xxx/xxx/13?name=zhangsan&age=18') ); // { name: 'zhangsan', id: 13, age: 18 }
console.log( transform('xxxx/xxx/xxx/xx/24?name=lisi&age=10') ); // { name: 'lisi', id: 24, age: 10}
    </script>
</body>

</html>